<template>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">


        <el-form-item label="设置名称">
            <el-input v-model="infoForm.name"></el-input>
        </el-form-item>
        <el-form-item label="设置价格">
            <el-input v-model="infoForm.price"></el-input>
        </el-form-item>
        <el-form-item>
            <el-select size="medium" v-model="infoForm.Type" placeholder="批量操作">
                <el-option style="width:200px;" v-for="item in operateOptions" :key="item" :value="item" :label="item">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="设置数量" prop="originNum">
            <el-input v-model="infoForm.originNum"></el-input>
        </el-form-item>
        <!-- <el-dropdown-item icon="el-icon-share" @click.native="$refs.file.click()" type="primary">
            设置商品图片
        </el-dropdown-item> -->
        <el-form-item>
            <el-button type="primary" @click="submitForm()">立即创建</el-button>
            <el-button @click="resetForm()">重置</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import { AddCommodity } from '@/api/admin/Commodity';
import { getHostKey } from '@/api/admin/Goods';
export default {
    data() {
        return {
            infoForm: {
                name: '',
                Type: '',
                originNum: '',
                price: ''
            }
        }
    },
    methods: {
        submitForm() {

            AddCommodity(this.infoForm).then(res => {
                console.log(res.data);
                if (res.data == 1) {
                    alert('添加成功')
                    this.$router.go(-1)
                }
            }
            ).catch(error => {
                console.log(error.response)
            })
        },
        GetHostKey() {
            getHostKey().then(res => {
                this.operateOptions = res.data
            })
        },
        resetForm() {
            this.ruleForm.name = '',
                this.ruleForm.date = '',
                this.ruleForm.address = ''
        },
        GetGoodsId(Goodstype, goodsName) {

            return new Promise((resolve, reject) => {
                // 模拟异步操作，例如 AJAX 请求
                getGoodId(Goodstype, goodsName).then(res => {
                    resolve(res.data)
                })
            });    // return await getGoodId(Goodstype, goodsName)


        }
    }, mounted() {
        this.GetHostKey()
    }
}
</script>
<style scoped>
.el-form {
    width: 500px;
    margin-left: 300px;
    margin-top: 50px;
}
</style>